﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"    
    xmlns:scott="clr-namespace:ScottIsAFool.WindowsPhone.Controls;assembly=ScottIsAFool.WindowsPhone"
    xmlns:adduplex="clr-namespace:AdDuplex;assembly=AdDuplex.AdControl.Silverlight"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:resources="clr-namespace:Url2Ringtone.Resources"
    xmlns:controlsPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls" 
    x:Class="Url2Ringtone.MainPage" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
	toolkit:TiltEffect.IsTiltEnabled="True">
	
	<phone:PhoneApplicationPage.Resources>
         <Style x:Key="styleLeftAligned" TargetType="ContentControl">
     	    <Setter Property="HorizontalAlignment" Value="Left"/>
			<Setter Property="Margin" Value="5,0,0,0"/>
         </Style>        
        <sys:String x:Key="ringtoneString">ringtone size: </sys:String>
		<Style x:Key="PivotMainStyle" TargetType="controls:Pivot">
			<Setter Property="Margin" Value="0"/>
			<Setter Property="Padding" Value="0"/>
			<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="ItemsPanel">
				<Setter.Value>
					<ItemsPanelTemplate>
						<Grid/>
					</ItemsPanelTemplate>
				</Setter.Value>
			</Setter>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="controls:Pivot">
						<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto"/>
								<RowDefinition Height="Auto"/>
								<RowDefinition Height="*"/>
							</Grid.RowDefinitions>
							<Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.RowSpan="3"/>
							<ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7"/>
							<controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
							<ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2" Height="480"/>
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
    </phone:PhoneApplicationPage.Resources>

	<phone:PhoneApplicationPage.FontFamily>
		<StaticResource ResourceKey="PhoneFontFamilyNormal"/>
	</phone:PhoneApplicationPage.FontFamily>
	<phone:PhoneApplicationPage.FontSize>
		<StaticResource ResourceKey="PhoneFontSizeNormal"/>
	</phone:PhoneApplicationPage.FontSize>
	<phone:PhoneApplicationPage.Foreground>
		<StaticResource ResourceKey="PhoneForegroundBrush"/>
	</phone:PhoneApplicationPage.Foreground>
	
	<toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>    

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
    	<controls:Pivot Title="{StaticResource AppName}" SelectionChanged="Pivot_SelectionChanged" x:Name="pivotMain" VerticalAlignment="Top" Height="612" Style="{StaticResource PivotMainStyle}">
    		<controls:Pivot.HeaderTemplate>
    			<DataTemplate>
    				<TextBlock Text="{Binding}" Style="{StaticResource PhoneTextAlmostLargeStyle}" Margin="12,0,-20,0"/>    		
    			</DataTemplate>
    		</controls:Pivot.HeaderTemplate>
    		<!--Pivot item one-->
    		<controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotRingtone, Mode=OneTime}">
    			<!--Double line list with text wrapping-->
    			<Grid>
    				<Grid.RowDefinitions>
    					<RowDefinition Height="100"/>
    					<RowDefinition Height="*"/>           	
    				</Grid.RowDefinitions>         
					
    				<StackPanel Orientation="Vertical" Grid.Row="0">
    					<StackPanel Orientation="Horizontal">
                            <toolkit:PhoneTextBox LengthIndicatorVisible="False" Hint="{Binding Source={StaticResource StringsManager}, Path=Strings.UrlHint, Mode=OneTime}" x:Name="txbxRingtoneUrl" Width="396" InputScope="Url" Text="{Binding CurrentItem.OriginalUrl, Mode=TwoWay}" KeyDown="txbxRingtoneUrl_KeyUp"/>
    						<Button x:Name="btnGo" Click="btnGo_Click" IsEnabled="{Binding Text, Converter={StaticResource LengthToBool}, ElementName=txbxRingtoneUrl}" 
    							Opacity="{Binding Text, Converter={StaticResource LengthToOpacity}, ElementName=txbxRingtoneUrl}" Height="48" Width="48">
    							<Button.Template>
    								<ControlTemplate>
    									<Image Height="48" Width="48" Source="{Binding IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=downloadringtone}"/>                   		
    								</ControlTemplate>                    	
    							</Button.Template>                     
    						</Button>
    					</StackPanel>
    					<StackPanel Orientation="Vertical" Visibility="{Binding IsDataLoaded, Converter={StaticResource InvertedVisibilityConverter}}">
    						<ProgressBar x:Name="progDownload" Value="{Binding PercentageChanged}" Maximum="100"/>
                            <TextBlock Text="{Binding Source={StaticResource StringsManager}, Path=Strings.Downloading, Mode=OneTime}" Style="{StaticResource PhoneTextSmallStyle}"/>
    					</StackPanel>
    				</StackPanel>

                    <StackPanel Orientation="Vertical" Grid.Row="1">
    				    <StackPanel Orientation="Vertical" IsHitTestVisible="{Binding DownloadingMP3, Converter={StaticResource InvertBoolean}}" Opacity="{Binding DownloadingMP3, Converter={StaticResource InvertedOpacityConverter}}">
                            <toolkit:PhoneTextBox LengthIndicatorVisible="False" Text="{Binding CurrentItem.RingtoneName, Mode=TwoWay}" Hint="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneName, Mode=OneTime}" x:Name="txbxRingtoneName" InputScope="Text" TextChanged="txbxRingtoneName_TextChanged"/>
    					    <TextBlock Text="{Binding CurrentItem.ToneSizeString}" Style="{StaticResource PhoneTextNormalStyle}" Height="35" Margin="20,0,0,0"/>
                            <CheckBox x:Name="chbxSaveRingtone" Content="{Binding Source={StaticResource StringsManager}, Path=Strings.SaveRingtoneLocally, Mode=OneTime}" IsChecked="{Binding CurrentItem.IsStoredLocally, Mode=TwoWay}"/>
    					    <MediaElement x:Name="ringtonePlayer" AutoPlay="True" CurrentStateChanged="ringtonePlayer_CurrentStateChanged"/>						    					
                        </StackPanel>
                        <TextBlock Text="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneInstructions, Mode=OneTime}" Margin="12,10,0,0" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}"/>
                    </StackPanel>
    			</Grid>                
    		</controls:PivotItem>
 
    		<!--Pivot item two-->
            <controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotHistory, Mode=OneTime}"> 
    			<!--Triple line list no text wrapping-->
				<Grid>		
					<Grid.RowDefinitions>
						<RowDefinition Height="*"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>					
					<toolkit:MultiselectList Grid.Row="0" x:Name="lbHistory" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="lbHistory_SelectionChanged"
						Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=false}">
						<toolkit:MultiselectList.ItemTemplate>
							<DataTemplate>
	    						<StackPanel Margin="0,0,0,17" VerticalAlignment="Top" Tap="StackPanel_Tap">
	    							<TextBlock Text="{Binding RingtoneName}" VerticalAlignment="Top" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
									<StackPanel Orientation="Horizontal" Margin="12,0,0,0">
										<Image Height="30" VerticalAlignment="Top" Source="{Binding Source={StaticResource viewModel}, Path=IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=appbar.save.rest}" Width="30" Visibility="{Binding IsStoredLocally, Converter={StaticResource VisibilityConverter}}" Margin="0,-6,0,1"/>
	    								<TextBlock Text="{Binding OriginalUrl}" TextWrapping="NoWrap" Margin="0,-6,0,0" Style="{StaticResource PhoneTextSubtleStyle}" Width="406"/>
									</StackPanel>
	    						</StackPanel>
	    					</DataTemplate>
						</toolkit:MultiselectList.ItemTemplate>
					</toolkit:MultiselectList>	    			
					<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top"
								Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=false}">
						<Image Height="30" VerticalAlignment="Top" Source="{Binding IsDarkTheme, Converter={StaticResource ImageUrlConverter}, ConverterParameter=appbar.save.rest}" Width="30" Margin="0,-6,0,0"/>
                        <TextBlock Text="{Binding Source={StaticResource StringsManager}, Path=Strings.RingtoneKey, Mode=OneTime}" Style="{StaticResource PhoneTextSmallStyle}" Margin="1,-4,12,0"/>
					</StackPanel>
                    <TextBlock VerticalAlignment="Top" HorizontalAlignment="Center" Text="{Binding Source={StaticResource StringsManager}, Path=Strings.NoItems, Mode=OneTime}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}"
							Visibility="{Binding Items.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=true}"/>
				</Grid>
    		</controls:PivotItem>

            <controls:PivotItem Header="{Binding Source={StaticResource StringsManager}, Path=Strings.PivotAbout, Mode=OneTime}">
    			<Grid>
    				<StackPanel Orientation="Vertical" Margin="0,0,0,48">
	    				<TextBlock Style="{StaticResource PhoneTextNormalStyle}" Height="62" TextWrapping="Wrap" Width="440" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="8,8,0,0" Text="WebTone © ScottIsAFool (@scottisafool) 2011 Version 1.1.0" />			            
						<StackPanel Orientation="Horizontal">
                            <Button x:Name="btnEmail" Content="{Binding Source={StaticResource StringsManager}, Path=Strings.EmailMe, Mode=OneTime}" HorizontalAlignment="Left" Margin="14,0,0,0" VerticalAlignment="Top" Width="207" d:LayoutOverrides="HorizontalAlignment" Click="btnEmail_Click" />
                            <Button x:Name="btnTwitter" Content="{Binding Source={StaticResource StringsManager}, Path=Strings.MyTwitter, Mode=OneTime}" Margin="0,0,14,0" VerticalAlignment="Top" HorizontalAlignment="Right" Click="btnTwitter_Click" Width="207" />
						</StackPanel>
                        <Button x:Name="btnWebsite" Content="{Binding Source={StaticResource StringsManager}, Path=Strings.MySite, Mode=OneTime}" VerticalAlignment="Top" Margin="14,0,0,0" Width="207" HorizontalAlignment="Left" Click="btnWebsite_Click" />
						<RichTextBox Width="420" HorizontalAlignment="Left">							
							<Paragraph>
                                <Run Text="{Binding Source={StaticResource StringsManager}, Path=Strings.GraphicsBy, Mode=OneTime}"/>
								<Hyperlink x:Name="linkMike" Click="linkMike_Click">Mike Hilton</Hyperlink>
							</Paragraph>
                            <Paragraph>
                                <Run Text="{Binding Source={StaticResource StringsManager}, Path=Strings.NotificationBoxText, Mode=OneTime}"/>
                                <Hyperlink x:Name="linkTomer" Click="linkTomer_Click">Tomer Shamam</Hyperlink>
                            </Paragraph>
						</RichTextBox>						
					</StackPanel>
                    <Button x:Name="btnRate" Content="{Binding Source={StaticResource StringsManager}, Path=Strings.RateApp, Mode=OneTime}" VerticalAlignment="Bottom" Click="btnRate_Click" Margin="0,0,0,-25"/>
				</Grid>
			</controls:PivotItem>
    	</controls:Pivot>
        <adduplex:AdControl AppId="2951" IsTest="False" Margin="0,5,8,0" d:LayoutOverrides="HorizontalMargin" VerticalAlignment="Bottom" BackgroundOpacity="0"/>
        <scott:ErrorBox x:Name="errorMessageBox" VerticalAlignment="Top" Margin="0"/>
		
    </Grid>
    
    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton Text="play" IconUri="/Icons/appbar.transport.play.rest.png" x:Name="btnPlayPause" Click="btnPlayPause_Click"/>
            <shell:ApplicationBarIconButton IconUri="/Icons/appbar.saveringtone.rest.png" Text="save" x:Name="btnSave" IsEnabled="False" Click="btnSave_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="menuSettings" Text="settings" Click="menuSettings_Click"/>
                <!--<shell:ApplicationBarMenuItem Text="MenuItem 2"/>-->
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>